package main;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class Catalog 
{
	public ArrayList<TheaterEvent> Events;
	
	public Catalog(String fileName)
	{
		Events=new ArrayList<TheaterEvent>();
		LoadEvents(fileName);
	}
	private void LoadEvents(String fileName)
	{
		int iLine=0;
		
		try 
		{
			Scanner sc=new Scanner(new FileInputStream(fileName));
			while(sc.hasNext())
			{
				try
				{
					iLine++;
					LoadEvent(sc.nextLine());
				}
				catch (Exception e)
				{
					System.out.println("Catalog: line "+iLine+" in "+fileName+" is corrupted");
				}
			}
		}
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		}
	}
	private void LoadEvent(String eventLine)
	{
		Scanner sc=new Scanner(eventLine);
		sc.useDelimiter("\\\"");
		String title=sc.next();
		sc.useDelimiter("\\s");
		sc.next();
		String date=sc.next();
		String time=sc.next();
		int capacity=sc.nextInt();
		Events.add(new TheaterEvent(title, date, time, capacity));		
	}
	public String toString()
	{
		String str="Catalogue:\n";
		for(TheaterEvent e : Events)
			str+=e+"\n";
		return str;
		
	}
}
